home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / intrvews / xgrab.lha / xgrab / ui / OGC / README < prev    next >
Encoding:
Text File  |  1990-03-06  |  7.2 KB  |  142 lines

  1. Copyright 1988 Hans-J. Boehm, Alan J. Demers
  2. This material may be freely distributed, provided this notice is retained.
  3. This material is provided as is, with no warranty expressed or implied.
  4. Use at your own risk.
  5.  
  6. GRAB Graph Layout and Browser System
  7. Copyright (c) 1989, Tera Computer Company
  8.  
  9.   This collector was developed as a part of research projects supported in
  10. part by the National Science Foundation and the Defense Advance Research
  11. Projects Agency.  The SPARC specific code was contributed by Mark Weiser
  12. at Xerox PARC.  Some of the improvements incorporated in this version were
  13. suggested by David Chase at Olivetti Research.
  14.  
  15.   This is intended to be a general purpose, garbage collecting storage
  16. allocator.  The algorithms used are described in:
  17.  
  18. Boehm, H., and M. Weiser, "Garbage Collection in an Uncooperative Environment",
  19. Software Practice & Experience, September 1988, pp. 807-820.
  20.  
  21.   Many of the ideas underlying the collector have previously been explored
  22. by others.  (We discovered recently that Doug McIlroy wrote a more or less
  23. similar collector that is part of version 8 UNIX (tm).)  However none of this
  24. work appears to have been widely disseminated.
  25.  
  26.   The tools for detecting storage leaks described in the above paper
  27. are not included here.  There is some hope that they might be released
  28. by Xerox in the future.
  29.  
  30.   Since the collector does not require pointers to be tagged, it does not
  31. attempt to insure that all inaccessible storage is reclaimed.  However,
  32. in our experience, it is more successful at reclaiming unused memory than most
  33. C programs using explicit deallocation.
  34.  
  35.   In the following, an "object" is defined to be a region of memory allocated
  36. by the routines described below.  
  37.  
  38.   Any objects not intended to be collected must be pointed to either
  39. from other such accessible objects, or from the registers,
  40. stack, data, or statically allocated bss segments.  It is assumed
  41. that all such pointers point to the beginning of the object.  (This does
  42. not disallow interior pointers; it simply requires that there must be a
  43. pointer to the beginning of every accessible object, in addition to any
  44. interior pointers.)
  45.   Note that pointers inside memory allocated by the standard "malloc" are not
  46. seen by the garbage collector.  Thus objects pointed to only from such a
  47. region may be prematurely deallocated.  It is thus suggested that the
  48. standard "malloc" be used only for memory regions, such as I/O buffers, that
  49. are guaranteed not to contain pointers.  Pointers in C language automatic,
  50. static, or register variables, are correctly recognized.
  51.   The collector is designed to minimize stack growth if link fields inside
  52. structures are allocated first.  (Normally only linked lists of lengths
  53. exceeding about 100000 will cause this to be noticable.)
  54.   Signal processing for most signals is deferred during collection.
  55.   As distributed, the collector produces garbage collection statistics
  56. during every collection.  Once the collector is known to operate properly,
  57. these can be suppressed by undefining the appropriate macros at the top
  58. of "runtime.h".  (The given statistics exhibit a few peculiarities.
  59. Things don't appear to add up for a variety of reasons, most notably
  60. fragmentation losses.  These are probably much more significant for the
  61. contrived program "test.c" than for your application.)
  62.   The collector is preconfigured to run on a Sun 3 workstation.  It will
  63. run on Sun 2s if the definition of STACKTOP in runtime.h is changed.
  64. It can also be reconfigured to run on a Vax under Berkeley UNIX, on a Sun 4
  65. under 4.0, or on a Sequent Symmetry. This requires changing a definition at
  66. the beginning of runtime.h.  (On a Sun 4, Makefile needs to be changed as
  67. indicated.  The collector is known not to run on a Sun 4 under at least
  68. some versions of 3.2.  The cause for this is not yet known.)  In all cases
  69. we assume that pointer alignment is consistent with that enforced by the
  70. standard C compilers.
  71.   For other machines, the following are likely to require change:
  72.  
  73. 1.  The parameters at the top of runtime.h
  74. 2.  allocobj.c
  75. 3.  The top level routine gcollect in alloc.c.  It contains assembly code
  76.     to mark registers.
  77. 4.  In-line assembly code in alloc.c.  (The mark algorithm is not recursive,
  78.     but may use the process stack as a marking stack.  This requires direct
  79.     access to the stack pointer.  Changes should be trivial on most
  80.     architectures.)
  81.  
  82.   For a different UN*X version or different machine using the Motorola 68000,
  83. Vax, SPARC, or 80386 architecture, it should frequently suffice to change
  84. definitions in runtime.h.
  85.  
  86.   The following routines are intended to be directly called by the user.
  87. Note that only gc_malloc and gc_init are necessary.  The remaining routines
  88. are used solely to enhance performance.  It is suggested that they be used
  89. only after initial debugging.
  90.  
  91. 1)  gc_init()
  92.     - called once before allocation to initialize the collector.
  93.  
  94. 2)  gc_malloc(nbytes)
  95.     - allocate an object of size nbytes.  Unlike malloc, the object is
  96.       cleared before being returned to the user.  (For even better performance,
  97.       it may help to expand the relevant part of gc_malloc in line.
  98.       This is done by the Russell compiler, for example.)  Gc_malloc will
  99.       invoke the garbage collector when it determines this to be appropriate.
  100.  
  101. 3)  gc_malloc_atomic(nbytes)
  102.     - allocate an object of size nbytes that is guaranteed not to contain any
  103.       pointers.  The returned object is not guaranteed to be cleeared.
  104.       (Can always be replaced by gc_malloc, but results in faster collection
  105.       times.  The collector will probably run faster if large character
  106.       arrays, etc. are allocated with gc_malloc_atomic than if they are
  107.       statically allocated.)
  108.  
  109. 4)  gc_free(object)
  110.     - explicitly deallocate an object returned by gc_malloc or
  111.       gc_malloc_atomic.  Not necessary, but can be used to minimize
  112.       collections if performance is critical.
  113.  
  114. 5)  expand_hp(number_of_4K_blocks)
  115.     - Explicitly increase the heap size.  (This is normally done automatically
  116.       if a garbage collection failed to reclaim enough memory.  Explicit
  117.       calls to expand_hp may prevent unnecessarily frequent collections at
  118.       program startup.)
  119.  
  120.   The global variable dont_gc can be set to a non-zero value to inhibit
  121. collections, e.g. during a time-critical section of code.  (This may cause
  122. otherwise unnecessary exansion of the process' memory.)
  123.   The variable non_gc_bytes, which is normally 0, may be changed to reflect
  124. the amount of memory allocated by the above routines that should not be
  125. considered as a candidate for collection.  Collections are inhibited
  126. if this exceeds a given fraction (currently 3/4) of the total heap size.
  127. The heap is simply expanded instead.  Careless use may, of course, result
  128. in excessive memory consumption.
  129.   
  130.   The two gc_malloc routines may be declared to return a suitable pointer
  131. type.  It is not intended that runtime.h be included by the user program.
  132. If only gc_malloc is intended to be used, it might be appropriate to define:
  133.  
  134. #define malloc(n) gc_malloc(n)
  135. #define calloc(m,n) gc_malloc((m)*(n))
  136.  
  137.   No attempt is made to use obscure names for garbage collector routines
  138. and data structures.  Name conflicts are possible.  (Running "nm gc.o"
  139. should identify names to be avoided.)
  140.  
  141.   Please address bug reports to boehm@rice.edu.
  142.